#pragma once

#include <list>

struct CHECKCONTACT
{
    DWORD	dwUin;			// contact uin (dword)
    HANDLE	hContact;		// hContact(HANDLE)
    int		PSD;			// value for calling setuserstatus (-1 for disable)
    BOOL	historyevent;	// set history event type (BOOL)
    BOOL	logtofile;		// set TRUE for write event to file (BOOL)
    int		icqeventtype;	// set db event type for history (int)
    int		dbeventflag;	// set additional db flags (int)
    BOOL	nottmpcontact;	// work with contact which not temporary (BOOL)
    BOOL	fornotonlist;	// work with contact which not on list (BOOL)
    BOOL	foroffline;		// work with offline contact (BOOL)
    BOOL	weofflinefor;	// work with contact which we offline for (BOOL)
};

struct UserToCheck
{
	DWORD dwUIN;
	DWORD dwCookie;
};

class CUserStatusSpy
{
public:
    CUserStatusSpy(CIcqProto* proto);
    ~CUserStatusSpy();
    void CheckUserStatus(HANDLE hContact);
    void SetUserStatus(DWORD dwUin, DWORD dwCookie, signed nStatus, HANDLE hContact);
    void CheckContact(CHECKCONTACT chk);
    void CheckSelfRemove();

private:
    void makeUserOffline(HANDLE hContact);
    DWORD icq_sendGetLocationInfo(HANDLE hContact, DWORD dwUIN, char *szUID);
	DWORD SendDetectionPacket2(HANDLE hContact, char* szQuery, char* szNotify);
	DWORD sendDetectionPacket(HANDLE hContact);
	void detectViaAuth(HANDLE hContact, DWORD dwCookie);

	void QueueCookie(DWORD dwCookie, DWORD dwUIN);
	icq_critical_section	m_oLock;
	std::list<UserToCheck>	m_deqUsers;

    CIcqProto*	m_pProto;
};

#define ICQEVENTTYPE_AUTH_REQUESTED  2006    //database event type
#define ICQEVENTTYPE_SELF_REMOVE  2007    //database event type
#define ICQEVENTTYPE_CLIENT_CHANGE 2009	  //database event type
#define ICQEVENTTYPE_CHECK_STATUS 2010 //database event type
#define ICQEVENTTYPE_IGNORECHECK_STATUS 2011 //database event type
#define ICQEVENTTYPE_YOU_ADDED 2012 //database event type
#define ICQEVENTTYPE_WAS_FOUND 2013 //db event )
#define ICQEVENTTYPE_CHECK_XSTATUS 2014 //database event type

#define CKT_CHECKSPAMBOT    0x40	// used in CUserStatusSpy::icq_sendGetLocationInfo and 
#define WAS_FOUND 0x80000000
